package com.macro.mall.controller;


import com.macro.mall.annotationUtil.CurrentUserName;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.util.HttpClient;
import com.macro.mall.dto.UmsWithdrawalApplyDto;
import com.macro.mall.service.UmsWithdrawalApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.ParseException;

/**
 * 提现记录管理
 */
@Controller
@ResponseBody
@RequestMapping("/withdrawal")
public class UmsWithdrawalApplyController {

    @Autowired
    private UmsWithdrawalApplyService withdrawalApplyService;

    /**
     * 获取店铺提现记录列表
     * @author 孙晓亮
     * @Date 2020年9月21日
     * @param currentUserName
     * @param umsWithdrawalApplyDto
     * @return
     */
    @ApiModelProperty("获取店铺提现记录列表")
    @RequestMapping(value = "/getStoreApplyList",method = RequestMethod.POST)
    public CommonResult getStoreApplyList (@CurrentUserName String currentUserName, @RequestBody UmsWithdrawalApplyDto umsWithdrawalApplyDto){
        CommonResult storeApplyList = null;
        try {
            storeApplyList = withdrawalApplyService.getStoreApplyList(currentUserName, umsWithdrawalApplyDto);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return storeApplyList;
    }

    /**
     * 查询店铺佣金总额，已结算，已提现，可提现金额
     * @author 孙晓亮
     * @Date 2020年9月21日
     * @param currentUserName
     * @return
     */
    @ApiModelProperty("查询店铺佣金总额，已结算，已提现，可提现金额")
    @RequestMapping(value = "/getMx",method = RequestMethod.GET)
    public CommonResult getStoreMx (@CurrentUserName String currentUserName){
        return withdrawalApplyService.getStoreMx(currentUserName);
    }

    /**
     * 审核店铺提现记录
     * @author 孙晓亮
     * @Date 2020年9月21日
     * @param request
     * @param userName
     * @param id
     * @param type 0通过 1不通过
     * @param reason 审核原因
     * @return
     */
    @ApiModelProperty("审核店铺提现记录")
    @RequestMapping(value = "audit",method = RequestMethod.POST)
    public CommonResult audit(HttpServletRequest request,
                                      @CurrentUserName String userName,
                                      @RequestParam Long id,
                                      @RequestParam Integer type,
                                      @RequestParam String reason){
        CommonResult commonResult = null;
        try {
            commonResult = this.withdrawalApplyService.audit(userName, id, type, reason, HttpClient.getIpAddress(request));
        } catch (RuntimeException e) {
            e.printStackTrace();
            commonResult = CommonResult.failed(e.getMessage());

        }
        return commonResult;
    }

    /**
     * 新增店铺提现记录
     * @param currentName
     * @param price 提现金额
     * @return
     */
    @ApiModelProperty("新增店铺提现记录")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public CommonResult add(@CurrentUserName String currentName, @RequestParam BigDecimal price){
            return withdrawalApplyService.add(currentName,price);

    }
}
